/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @param {number} k
 * @return {boolean}
 */
var findTarget = function(root, k) {
  let result = [];
  function preView(node) {
    if(!node) return;
    result.push(node.val);
    preView(node.left);
    preView(node.right);
  }
  preView(root);
  result.sort((a, b) => a - b);
  let i = 0, j = result.length - 1;
  while(i < j) {
    if(result[i] + result[j] == k) {
      return true;
    } else {
      if(result[i] + result[j] > k) {
        j--;
      } else {
        i++;
      }
    }
  }
  return false;
};
